package com.wzy.vx.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @ProjectName: vx
 * @Package: com.wzy.vx.config
 * @ClassName: WechatOpenConfig
 * @Author: Administrator
 * @Description: ${description}
 * @Date: 2019/3/20 15:31
 * @Version: 1.0
 */
@Component
public class WechatOpenConfig {
    @Autowired
    private WechatUserConfig userConfig;
    @Bean
    public WxMpService wxOpenService(){
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        //基于内存的
        WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
        wxMpConfigStorage.setAppId(userConfig.getOpenAppId());
        wxMpConfigStorage.setSecret(userConfig.getOpenAppSecret());
        return  wxMpConfigStorage;
    }

}
